package states;
import geom.Position2i;
import gui.Button;
import gui.ButtonMenu;
import gui.ChangeStateButton;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import various_tmp.Game;


public class TitleState extends State
{
	
	
  public static final int ID = 0; 
  private Image logo;
  
  private Button new_game, options;
  private ButtonMenu menu;
  
  private Position2i menu_position;

  
  @Override
  public int getID()
  {
    return Game.TITLE_STATE;
  }
  
  @Override
  public void init(GameContainer container, StateBasedGame game) throws SlickException 
  {
    logo= new Image("data/ship.png");
    
    new_game = new ChangeStateButton("New Game", Game.GAME_STATE);
    options = new ChangeStateButton("Options", Game.OPTIONS_STATE);
	
	
  	menu = new ButtonMenu();
  	menu.add(new_game);
  	menu.add(options);
  	menu.setSelected(0);
  	
  	menu_position = new Position2i(110, 155);
	
  }

  @Override
  public void update(GameContainer container, StateBasedGame game, int delta)
  {
  }
  
  @Override
  public void render(GameContainer container, StateBasedGame game, Graphics g) 
  {
    g.drawImage(logo,200,200);
    menu.draw(this.menu_position.x, this.menu_position.y, g);

  }
  
  
  //************************************************************************
  // Management inputs
  
  @Override
  public void keyPressed(int key, char c) {
     switch(key){
      case Input.KEY_DOWN :
        menu.next();
        break;
      case Input.KEY_UP : 
    	  menu.prev();
    	  break;
      }
  }
  
  @Override
  public void keyReleased(int key, char c) {

      if (key == Input.KEY_ENTER)
          menu.getSelected().action();
      
  }


}
